package com.techsoft.executor;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CommentExecutor {
	
	
	public static String  closureComment(String str,String prefix,String suffix){
		
		if(str == null || "".equals(str)){
			return "";
		}
		StringBuffer sbBuffer = new StringBuffer();
		String regex =  prefix+"(.|\\s*.)*?"+suffix; //以换行符为结尾
		Pattern pattern = Pattern.compile(regex);
		Matcher matcher = pattern.matcher(str);
		while (matcher.find()) {
			matcher.appendReplacement(sbBuffer, "");
		}
		matcher.appendTail(sbBuffer);
		return sbBuffer.toString();
	}
	
	public static String  autoClosureComment(String str,String start){
		
		if(str == null || "".equals(str)){
			return "";
		}
		StringBuffer sbBuffer = new StringBuffer();
		String regex =  start+".*$?";
		Pattern pattern = Pattern.compile(regex);
		Matcher matcher = pattern.matcher(str);
		while (matcher.find()) {
			matcher.appendReplacement(sbBuffer, "");
		}
		matcher.appendTail(sbBuffer);
		return sbBuffer.toString();
	}
}
